home *** CD-ROM | disk | FTP | other *** search
/ The Pacifier Press Kit / The Pacifier Press Kit.iso / pc / Program.dxr / Internal_69_Typewriter Effect.ls < prev    next >
Encoding:
Text File  |  2005-02-15  |  3.8 KB  |  125 lines

  1. property pSprite, pMember, pText, pChars, pIndex, pStartTime, pActive, pPeriodBase, pPeriod, pSoundChannel, pSound
  2.  
  3. on getBehaviorDescription me
  4.   return "TYPEWRITER EFFECT" & RETURN & RETURN & "A field or text sprite with this behavior attached displays as if it was being typed onto the screen. " & "To use, place a field or text cast member in place on the stage; and type in the message you want to appear; then attach this behavior. " & "The type can begin to display automatically in the first frame the sprite appears in, or it can be set to wait for an mActive message. " & "You can set the amount of time to wait between characters, and play a sound for each letter." & RETURN & RETURN & "PARAMETERS:" & RETURN & " - Autotype when sprite appears" & RETURN & " - Time between characters" & RETURN & " - Sound to play when character appears" & RETURN & " - Sound channel to use" & RETURN & RETURN & "PERMITTED TYPES:" & RETURN & " - Text or Fields"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Types text onto screen into 'visible' or 'invisible' text field. " & "An accompanying sound can be assigned to play as text appears."
  9. end
  10.  
  11. on beginSprite me
  12.   mInitialize(me)
  13. end
  14.  
  15. on endSprite me
  16.   pMember.text = pText
  17. end
  18.  
  19. on prepareFrame me
  20.   mType(me)
  21. end
  22.  
  23. on mInitialize me
  24.   pSprite = sprite(me.spriteNum)
  25.   pMember = pSprite.member
  26.   pMember.boxType = #fixed
  27.   pText = pMember.text
  28.   pChars = pText.length
  29.   if pChars < 1 then
  30.     vError = mErrorAlert(me, #noText)
  31.   end if
  32.   pMember.text = " "
  33.   pIndex = 0
  34.   pPeriod = integer(pPeriodBase * 1000)
  35.   pStartTime = the milliSeconds - pPeriod
  36.   if pSoundChannel then
  37.     vError = 0
  38.     if pSound = #none then
  39.       vError = 1
  40.     else
  41.       if member(pSound).type <> #sound then
  42.         vError = 1
  43.       end if
  44.     end if
  45.     if vError then
  46.       pSoundChannel = 0
  47.       vError = mErrorAlert(me, #noSound)
  48.     end if
  49.   end if
  50. end
  51.  
  52. on mType me
  53.   if pActive then
  54.     if pIndex >= pChars then
  55.       pActive = 0
  56.     else
  57.       vMillis = the milliSeconds
  58.       if (vMillis - pStartTime) > pPeriod then
  59.         pIndex = pIndex + 1
  60.         if pIndex = 1 then
  61.           pMember.text = pText.char[1]
  62.         else
  63.           pMember.text = pMember.text & pText.char[pIndex]
  64.         end if
  65.         if pSoundChannel then
  66.           puppetSound(pSoundChannel, 0)
  67.           puppetSound(pSoundChannel, pSound)
  68.         end if
  69.         pStartTime = the milliSeconds
  70.       end if
  71.     end if
  72.   end if
  73. end
  74.  
  75. on mErrorAlert me, vError, vData
  76.   vBehaviorname = string(me)
  77.   delete word 1 of vBehaviorname
  78.   delete char -30001 of vBehaviorname
  79.   delete char -30001 of vBehaviorname
  80.   case vData.ilk of
  81.     #void:
  82.       vData = "<void>"
  83.     #symbol:
  84.       vData = "#" & vData
  85.   end case
  86.   case vError of
  87.     #noText:
  88.       alert("CANCEL: Sprite MUST contain formatted text to display correctly")
  89.     #noSound:
  90.       alert("CANCEL: Sound channel should be set to 0 if no sound is selected")
  91.   end case
  92. end
  93.  
  94. on mActive me
  95.   pActive = 1
  96. end
  97.  
  98. on isOKToAttach me, aSpriteType, aSpriteNum
  99.   case aSpriteType of
  100.     #graphic:
  101.       return getPos([#field, #text], sprite(aSpriteNum).member.type) <> 0
  102.     #script:
  103.       return 0
  104.   end case
  105. end
  106.  
  107. on getPropertyDescriptionList me
  108.   vPDList = [:]
  109.   setaProp(vPDList, #pActive, [#comment: "Autostart (alternative is wait for mActive message)", #format: #boolean, #default: 1])
  110.   setaProp(vPDList, #pPeriodBase, [#comment: "Time to wait between typed characters (seconds)", #format: #float, #default: 0.25, #range: [#min: 0.001, #max: 2.0]])
  111.   setaProp(vPDList, #pSound, [#comment: "Sound for typed characters", #format: #sound, #default: #none])
  112.   setaProp(vPDList, #pSoundChannel, [#comment: "Channel for sound (0 for no sound)", #format: #integer, #default: 0, #range: [0, 1, 2, 3, 4, 5, 6, 7, 8]])
  113.   return vPDList
  114. end
  115.  
  116. on exitFrame
  117.   if pIndex = pChars then
  118.     if the frame = 1 then
  119.       go(the frame + 1)
  120.     end if
  121.   else
  122.     go(the frame)
  123.   end if
  124. end
  125.